package guda.house.dal.dao.impl;

import guda.grape.autogen.common.BaseDAO;
import guda.house.dal.dao.BillPayDAO;
import guda.house.dal.dataobject.BillPayDO;
import guda.grape.autogen.common.page.BaseQuery;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class BillPayDAOImpl extends BaseDAO implements BillPayDAO {

    @Override
	public Long insert(BillPayDO billPay) {
	      try {
                return (Long) getSqlMapperW().insert("bill_pay.insert",billPay);
          } catch (Exception e) {
                throw new RuntimeException(e);
          }

	}

    @Override
	public BillPayDO getBillPayById(Long payId) {
	    return (BillPayDO)getSqlMapClientTemplate().queryForObject("bill_pay.getBillPayById", payId);
	}

    @Override
	public boolean delBillPayById(Long payId) {
	    int num = 0;
        try {
            num = getSqlMapperW().delete("bill_pay.delBillPayById",payId);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        if(num>0){
            return true;
        }else{
            return false;
        }
	}

    @Override
	public List<BillPayDO> getBillPayByIds(List idsList) {
        Map m = new HashMap();
        m.put("idsList",idsList);
		return getSqlMapClientTemplate().queryForList("bill_pay.selectByIds", m);
	}

    @Override
	public void cleanAutoIncrement(Long payId) {
	    try {
            getSqlMapperW().update("bill_pay.cleanAutoIncrement",payId);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
	}

    @Override
    public List<BillPayDO> selectForPage(BaseQuery baseQuery) {
        return getSqlMapClientTemplate().queryForList("bill_pay.selectForPage", baseQuery);
    }

    @Override
    public int countForPage(BaseQuery baseQuery) {
        return (Integer)getSqlMapClientTemplate().queryForObject("bill_pay.countForPage",baseQuery);
    }

    @Override
    public void updateByIdSelective(BillPayDO billPay) {
        try {
            getSqlMapperW().update("bill_pay.updateByIdSelective",billPay);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public List<BillPayDO> selectForPayedLog(BaseQuery baseQuery) {
        return getSqlMapClientTemplate().queryForList("bill_pay.selectForPayedLog", baseQuery);
    }

    @Override
    public int countForPayedLog(BaseQuery baseQuery) {
        return (Integer)getSqlMapClientTemplate().queryForObject("bill_pay.countForPayedLog",baseQuery);
    }

    @Override
    public List<BillPayDO> statPay(List<Long> suitIdList, String gmtStart, String gmtEnd) {
        Map m = new HashMap();
        m.put("suitIdList",suitIdList);
        m.put("gmtStart",gmtStart);
        m.put("gmtEnd",gmtEnd);
        return getSqlMapClientTemplate().queryForList("bill_pay.statPay", m);
    }

    @Override
    public List<BillPayDO> getByInvoiceId(long invoiceId) {
        return getSqlMapClientTemplate().queryForList("bill_pay.getByInvoiceId", invoiceId);
    }

}

